﻿using CatUtils.Utils.Currency.IoUtils;
using CatUtils.Utils.Helper;
using CatUtils.Utils.SpecialUtils.WinConsole;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MusicPhotograph.VideoHelper
{
    internal class ImageMagickHelper
    {
        /// <summary>
        //命令行工具所处位置
        /// </summary>
        public readonly static string MagickExePath = StaticValue.BinImportPath + "magick.exe";

        /// <summary>
        /// 重写文件大小
        /// </summary>

        public readonly static string ResizeImgTemp = StaticValue.TempPath + "resize.png";
        /// <summary>
        /// 高斯模糊
        /// </summary>

        public readonly static string BlurmgTemp = StaticValue.TempPath + "blur.png";

        /// <summary>
        /// 合并两张图
        /// </summary>
        public readonly static string MergeImgTemp = StaticValue.TempPath + "merge.png";

        /// <summary>
        /// 添加文字图片缓存
        /// </summary>
        public readonly static string AddTextTemp = StaticValue.TempPath + "AddTextTemp.png";

        /// <summary>
        /// 字库文件路径
        /// </summary>
        public readonly static string FontPath = StaticValue.BinImportPath + "NotoSansHans-Bold.otf";

        /// <summary>
        /// 调整图片大小的命令
        /// </summary>
        public readonly static string ResizeCommand = " convert -resize 1920x1080  \"{0}\" \"{1}\"";

        /// <summary>
        /// 高斯模糊 当前参数：80 模糊区间35PX
        /// </summary>
        public readonly static string BlurCommad = string.Format(" convert -resize 1920x1080! -blur 80x35 \"{0}\" \"{1}\"", ResizeImgTemp, BlurmgTemp);

        /// <summary>
        /// 原图+模糊图拼接
        /// </summary>
        public readonly static string MergeCommad = string.Format(" convert \"{0}\" -compose over \"{1}\" -gravity center -composite  \"{2}\"", BlurmgTemp, ResizeImgTemp, MergeImgTemp);

        /// <summary>
        /// 添加图片名字
        /// </summary>
        public readonly static string AddTextCommad = " convert \"{0}\"  -font \"{1}\" -pointsize 30  -fill white  -weight bold -draw \"text 0,30'{2}'\" -gravity Center -append    {3}";

        /// <summary>
        /// 创建视频需要的模糊图
        /// </summary>
        /// <param name="FileName"></param>
        /// <param name="Tip"></param>
        /// <returns></returns>
        public string CreateMoiveImg(string FileName, string Tip)
        {
            new FloderHelper().FloderExits(StaticValue.BinImportPath, true);

            Console.WriteLine(new ProcessHelper().RunCmdReadOut(MagickExePath, string.Format(ResizeCommand, FileName, ResizeImgTemp)));
            Console.WriteLine(new ProcessHelper().RunCmdReadOut(MagickExePath, BlurCommad));
            Console.WriteLine(new ProcessHelper().RunCmdReadOut(MagickExePath, MergeCommad));
            Console.WriteLine(new ProcessHelper().RunCmdReadOut(MagickExePath, string.Format(AddTextCommad, MergeImgTemp, FontPath, Tip + new FileNameHelper().GetFileNameWithoutExtension(FileName), AddTextTemp)));
            Console.WriteLine("创建图片成功。");
            return AddTextTemp;
        }
    }
}